Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Build::getenv instead of env::var* in anywhere that makes sense #1103

Merged
merged 22 commits into from
Jun 25, 2024

Conversation

NobodyXu
Copy link
Collaborator

So that we would get:

  • recompilation when the env is changed
  • cached env

Also some optimisation

Only call `self.getenv("RUSTC_LINKER")` if necessary

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
`RwLock` would enable readers to run in parallel.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Use `Path` instead of `PathBuf` to avoid alloc

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Cache everything in there in `apple_versions_cache`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Cache in `apple_sdk_root_cache` if possible

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Only call `to_string_lossy()` if necessary

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
src/lib.rs Outdated Show resolved Hide resolved
Avoid one heap allocation that is de-allocated immediately
src/lib.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to ban std::env::var and std::env::var_os via. Clippy's disallowed_methods functionality? And then explicitly allow it inside the implementation of getenv

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
under `#[cfg(test)]`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@NobodyXu NobodyXu requested review from thomcc and madsmtm June 24, 2024 14:49
@NobodyXu
Copy link
Collaborator Author

Might make sense to ban std::env::var and std::env::var_os via. Clippy's disallowed_methods functionality? And then explicitly allow it inside the implementation of getenv

Thanks!

Applied the suggestion, and turns out that the entire windows_registry is using env::var*

Took me a while to change them to use a generic function.

cc @thomcc @madsmtm

@NobodyXu
Copy link
Collaborator Author

cc @madsmtm This PR should cover most env variables in #906

If there's any missing, feel free to open a comment.

The generic params would cause every function to be mono-ed twice,
result in longer compilation time and larger binary.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Create a new local fn `has_msbuild_version` in `find_vs_version`
to make the invocation easier.

Also add `#[inline(always)]` to `has_msbuild_version` since it is only
used in `find_vs_version`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@NobodyXu
Copy link
Collaborator Author

Updated the code to remove any generics in windows_regsitry.

Having generics would make cc takes longer to compile and generate larger binary, and I don't think it would give us any improvements to performance.

@@ -3534,7 +3540,7 @@ impl Build {
// Loop through PATH entries searching for each toolchain. This ensures that we
// are more likely to discover the toolchain early on, because chances are good
// that the desired toolchain is in one of the higher-priority paths.
env::var_os("PATH")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this change causes crates to rebuild on Windows any time the PATH changes. Anecdotally, that seems to have a pretty high false positive rate, and since some PATH changes are associated with tools like rust-analyer that run constantly in the background, this can make it so that every build is a complete rebuild in some setups / with some dependencies. See for example BLAKE3-team/BLAKE3#324. I might file this as an issue shortly, but I wanted to mention it real quick before I forget.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can special-case PATH here?

For example, Update the getenv to not emit anything for PATH

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just crosslinking, should be fixed in #1215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants